<template>
  <el-dialog width="66%" title="恢复记录" v-model="dialogVisible" modal @close="closeDialog" draggable
    :close-on-click-modal="false" :append-to-body="true">
    <el-form :inline="true" :model="queryParam" class="demo-form-inline">
      <el-form-item label="恢复日期">
        <el-date-picker size="small" v-model="recoveryDate" type="daterange" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="恢复人">
        <el-input size="small" v-model="queryParam.createByName" placeholder="请输入恢复人名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" border style="width: 100%" height="30vh">
      <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
      <el-table-column v-for="item of tableProps" :key="item.props" :prop="item.prop" :label="item.title"
        :width="item.width">
      </el-table-column>
    </el-table>
    <pagination ref="pagination" style="margin-top: 10px" :totalCount="totalCount" @pagination="pagination">
    </pagination>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closeDialog" size="mini">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { pageRecoveryList } from '@/api/sys/backups'
import moment from 'moment'
export default {
  name: 'recoveryDialog',
  data() {
    return {
      dialogVisible: false,
      tableData: [],
      totalCount: 0, //总数
      //查询条件
      searchModel: {
        pageNo: 1,
        pageSize: 10,
      },
      queryParam: {},
      recoveryDate: [],
      tableProps: [
        { title: '恢复时间', prop: 'createTime', width: '', checked: true },
        { title: '恢复人', prop: 'createByName', width: '', checked: true },
        { title: '文件名称', prop: 'fileName', width: '', checked: true },
      ],
    }
  },
  methods: {
    init() {
      this.dialogVisible = true
      this.loadData()
    },
    onSubmit() {
      this.$refs.pagination.resetPagination()
    },
    loadData() {
      if (this.recoveryDate != null && this.recoveryDate.length > 0) {
        this.queryParam.beginTime = moment(this.recoveryDate[0]).format('YYYY-MM-DD 00:00:00')
        this.queryParam.endTime = moment(this.recoveryDate[1]).format('YYYY-MM-DD 23:59:59')
      } else {
        this.queryParam.beginTime = null
        this.queryParam.endTime = null
      }
      const param = Object.assign(this.queryParam, this.searchModel)
      pageRecoveryList(param)
        .then((res) => {
          if (res.data.code === 200) {
            this.tableData = res.data.data.records
            this.totalCount = res.data.data.total
          } else {
            this.$message.error(res.data.message)
          }
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    pagination(val) {
      this.searchModel.pageNo = val.page
      this.searchModel.pageSize = val.limit
      this.loadData()
    },
    closeDialog() {
      this.dialogVisible = false
      this.queryParam = {}
      this.recoveryDate = []
    },
  },
}
</script>

<style scoped></style>
